package com.larsgard.gedviewer.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.Widget;

public class VisitorContent extends Composite {

    private static VisitorContentUiBinder uiBinder = GWT.create(VisitorContentUiBinder.class);

    interface VisitorContentUiBinder extends UiBinder<Widget, VisitorContent> {
    }

    @UiField
    PasswordTextBox passwordBox;

    public VisitorContent() {
	initWidget(uiBinder.createAndBindUi(this));
	passwordBox.setFocus(true);
    }

    @UiHandler("passwordBox")
    public void pressEnter(KeyPressEvent keypress) {
	if (keypress.getCharCode() == KeyCodes.KEY_ENTER) {
	    String param = (Window.Location.getHref().contains("?")) ? "&pwd=" : "?pwd=";
	    String url = Window.Location.getHref() + param + passwordBox.getText();
	    Window.Location.assign(url);
	}
    }

}
